package doc

import (
	"github.com/go-emix/utils"
	"os"
	"strconv"
)

type ApiDoc struct {
	Code        int
	Description string
}

var docFile *os.File

var docStr = "apidoc"

func init() {
	if utils.FileIsExist(docStr) {
		_ = os.Remove(docStr)
	}
	file, err := os.Create(docStr)
	utils.PanicError(err)
	docFile = file
}

func CloseFile() {
	err := docFile.Close()
	utils.PanicError(err)
}

func GenDoc(doc ...ApiDoc) {
	for _, d := range doc {
		_, _ = docFile.WriteString("code: " + strconv.Itoa(d.Code) + ",des: " + d.Description + "\n")
	}
}
